//
//  HEGuideViewController.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/9/28.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEGuideViewController.h"
#import "HELoginViewController.h"
#import <SafariServices/SafariServices.h>
#import "HEProtocalViewController.h"

@interface HEGuideViewController ()<UIScrollViewDelegate>

@property (copy, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) UIView *protocal;

@end

@implementation HEGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initUI];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    BOOL hasAgreenProtocal = [kUserDefaults boolForKey:KHasAgreenProtocal];
    
    if (!hasAgreenProtocal) {
        HEProtocalViewController *pv = [[HEProtocalViewController alloc] init];
        pv.modalPresentationStyle = UIModalPresentationCustom;
        [self presentViewController:pv animated:NO completion:nil];
    }
}

- (void)initUI {
    

    NSArray *imgs = @[@"guide1", @"guide2", @"guide3", @"guide4"];
    
    _scrollView = [[UIScrollView alloc] init];
    _scrollView.frame = self.view.bounds;
    _scrollView.bounces = NO;
    _scrollView.pagingEnabled = YES;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.scrollEnabled = YES;
    _scrollView.delegate = self;
            
    NSInteger cont = imgs.count;
    for (NSInteger i = 0; i < cont; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed: imgs[i]]];
        imageView.userInteractionEnabled = YES;
        CGRect frame = CGRectZero;
        imageView.contentMode = UIViewContentModeScaleAspectFill;

        frame.origin.x = i * _scrollView.frame.size.width;
        frame.size = _scrollView.frame.size;
        imageView.frame = frame;
        imageView.clipsToBounds = YES;
        [_scrollView addSubview:imageView];
        
         if(i == cont - 1) {
            //开启图片的用户点击功能
            imageView.userInteractionEnabled = YES;
            //加个按钮
            UIButton *button = [[UIButton alloc]init];
            [imageView addSubview:button];
             
             button.sd_layout
             .widthIs( KScreenWidth)
             .heightIs( kScreenHeight)
             .centerXEqualToView(imageView)
             .bottomSpaceToView(imageView, 0);
            
            button.backgroundColor = [UIColor clearColor];
//            [button setTitle:@"立即体验" forState:UIControlStateNormal];
            button.titleLabel.font = [UIFont boldSystemFontOfSize:16];
            [button addTarget:self action:@selector(enter) forControlEvents:UIControlEventTouchUpInside];
         }
    }
    _scrollView.contentSize = CGSizeMake(cont * _scrollView.frame.size.width, _scrollView.frame.size.height);

    [self.view addSubview:_scrollView];
}

- (void)enter  {
    
    [kUserDefaults setBool:YES forKey:KHasShowGuide];
    HELoginViewController *loginVC = [[HELoginViewController alloc] init];
    loginVC.modalPresentationStyle = UIModalPresentationFullScreen;
    loginVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:loginVC animated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
